package com.hc.java.fiber;

import co.paralleluniverse.fibers.Fiber;

import java.util.concurrent.ExecutionException;

/**
 * @author huangchao E-mail:fengquan8866@163.com
 * @version 创建时间：2024/6/21 8:41
 */
public class HelloFiber {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        long start = System.currentTimeMillis();

        Runnable r = HelloFiber::calc;
        int size = 10000;

        Fiber<Void>[] fibers = new Fiber[size];
        for (int i = 0; i < fibers.length; i++) {
            fibers[i] = new Fiber<>(HelloFiber::calc);
        }

        for (int i = 0; i < fibers.length; i++) {
            fibers[i].start();
        }

        for (int i = 0; i < fibers.length; i++) {
            fibers[i].join();
        }

        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }

    static void calc() {
        int result = 0;
        for (int m = 0; m < 10000; m++) {
            for (int i = 0; i < 200; i++) result += i;
        }
    }
}
